import {reqGetUserAddressList , reqTradeInfoData} from '@/api'

const state = {
    userAddList:[],
    tradeInfoList:[]
}

const actions = {
    // 获取用户地址
    async getUserAdd({commit}){
        const res = await reqGetUserAddressList();
        if(res.code === 200){
            commit("SAVE_USER_ADD",res.data)
        }else{
            console.log(res.message);
        }
    },

    // 获取订单信息
    async getTradeInfo({commit}){
        const res = await reqTradeInfoData();
        if(res.code === 200){
            commit("SAVE_TRADE_INFO",res.data)
        }else{
            console.log(res.message);
        }
    }
}

const mutations = {
    // 存储用户地址
    SAVE_USER_ADD(state,userAdd){
        state.userAddList = userAdd;
    },

    // 存储商品数据
    SAVE_TRADE_INFO(state,tradeInfo){
        state. tradeInfoList = tradeInfo;
    }
}

const getters = {
    // 商品列表
    detailArrayList(state){
        return state.tradeInfoList.detailArrayList
    },

    // 商品总金额
    originalTotalAmount(state){
        return state.tradeInfoList.originalTotalAmount
    },

    // 应付金额
    totalAmount(state){
        return state.tradeInfoList.totalAmount
    },

    // 商品总数
    totalNum(state){
        return state.tradeInfoList.totalNum
    },

    // 订单编号
    tradeNo(state){
        return state.tradeInfoList.tradeNo
    }
}


export default {
    namespaced:true,
    state,
    actions,
    mutations,
    getters
}